package com.zmn.mcc.common.enums;

import com.google.common.collect.Lists;
import com.zmn.mcc.common.constant.DpermitConsts;

import java.util.List;

/**
 * 数据权限类型枚举
 *
 * @author heguanghua
 * @since 2020/06/12 11:28
 */
public enum DpermitEnum {

    ORGANIZE(DpermitConsts.TYPE_ORGANIZE, DpermitConsts.TYPE_ORGANIZE, 0, "组织架构"),
    ORGANIZE_PLAT(DpermitConsts.TYPE_ORGANIZE_PLAT, DpermitConsts.TYPE_ORGANIZE, DpermitConsts.ORGANIZE_LEVEL_PLAT, "平台"),
    ORGANIZE_REGION(DpermitConsts.TYPE_ORGANIZE_REGION, DpermitConsts.TYPE_ORGANIZE, DpermitConsts.ORGANIZE_LEVEL_REGION, "大区"),
    ORGANIZE_SUB(DpermitConsts.TYPE_ORGANIZE_SUB, DpermitConsts.TYPE_ORGANIZE, DpermitConsts.ORGANIZE_LEVEL_SUB, "子公司"),
    ORGANIZE_SP(DpermitConsts.TYPE_ORGANIZE_SP, DpermitConsts.TYPE_ORGANIZE, DpermitConsts.ORGANIZE_LEVEL_GRANDSON, "服务商"),

    DEPT(DpermitConsts.TYPE_DEPT, DpermitConsts.TYPE_DEPT, 0, "部门"),
    DEPT_L1(DpermitConsts.TYPE_DEPT_L1, DpermitConsts.TYPE_DEPT, DpermitConsts.DEPT_LEVEL_ONE, "一级部门"),
    DEPT_L2(DpermitConsts.TYPE_DEPT_L2, DpermitConsts.TYPE_DEPT, DpermitConsts.DEPT_LEVEL_TWO, "二级部门"),
    DEPT_L3(DpermitConsts.TYPE_DEPT_L3, DpermitConsts.TYPE_DEPT, DpermitConsts.DEPT_LEVEL_THRE, "三级部门"),

    AREA(DpermitConsts.TYPE_AREA, DpermitConsts.TYPE_AREA, 0, "区域"),
    AREA_PROVINCE(DpermitConsts.TYPE_AREA_PROVINCE, DpermitConsts.TYPE_AREA, DpermitConsts.AREA_LEVEL_PROVINCE, "省"),
    AREA_CITY(DpermitConsts.TYPE_AREA_CITY, DpermitConsts.TYPE_AREA, DpermitConsts.AREA_LEVEL_CITY, "市"),
    AREA_COUNTY(DpermitConsts.TYPE_AREA_COUNTY, DpermitConsts.TYPE_AREA, DpermitConsts.AREA_LEVEL_COUNTY, "区县"),

    COOPERATION(DpermitConsts.TYPE_COOPERATION, DpermitConsts.TYPE_COOPERATION, 0, "合作"),
    COOPERATION_PLAT(DpermitConsts.TYPE_COOPERATION_PLAT, DpermitConsts.TYPE_COOPERATION, DpermitConsts.COOPERATION_LEVEL_PLAT, "下单平台"),
    COOPERATION_ONE(DpermitConsts.TYPE_COOPERATION_ONE, DpermitConsts.TYPE_COOPERATION, DpermitConsts.COOPERATION_LEVEL_COMPANY, "一级合作"),
    COOPERATION_TWO(DpermitConsts.TYPE_COOPERATION_TWO, DpermitConsts.TYPE_COOPERATION, DpermitConsts.COOPERATION_LEVEL_CHANNEL, "二级合作"),

//    CATEGORY(DpermitConsts.TYPE_CATEGORY, DpermitConsts.TYPE_CATEGORY, 0, "分类"),
//    CATEGORY_SEVR(DpermitConsts.TYPE_CATEGORY_SEVR, DpermitConsts.TYPE_CATEGORY, 1, "服务分类"),
//    CATEGORY_PROD1(DpermitConsts.TYPE_CATEGORY_PROD1, DpermitConsts.TYPE_CATEGORY, 2, "一级产品分类"),
//    CATEGORY_PROD2(DpermitConsts.TYPE_CATEGORY_PROD2, DpermitConsts.TYPE_CATEGORY, 3, "二级产品分类"),

    CUBE(DpermitConsts.TYPE_CUBE, DpermitConsts.TYPE_CUBE, 0, "大数据报表"),
    CUBE_L1(DpermitConsts.TYPE_CUBE_L1, DpermitConsts.TYPE_CUBE, DpermitConsts.CUBE_LEVEL_ONE, "一级"),
    CUBE_L2(DpermitConsts.TYPE_CUBE_L2, DpermitConsts.TYPE_CUBE, DpermitConsts.CUBE_LEVEL_TWO, "二级"),
    CUBE_L3(DpermitConsts.TYPE_CUBE_L3, DpermitConsts.TYPE_CUBE, DpermitConsts.CUBE_LEVEL_THRE, "三级"),
    CUBE_L4(DpermitConsts.TYPE_CUBE_L4, DpermitConsts.TYPE_CUBE, DpermitConsts.CUBE_LEVEL_FOUR, "四级"),

    MEASURE(DpermitConsts.TYPE_MEASURE, DpermitConsts.TYPE_MEASURE, 0, "大数据指标"),
    MEASURE_L1(DpermitConsts.TYPE_MEASURE_L1, DpermitConsts.TYPE_MEASURE, DpermitConsts.MEASURE_LEVEL_DATASET, "数据集"),
    MEASURE_L2(DpermitConsts.TYPE_MEASURE_L2, DpermitConsts.TYPE_MEASURE, DpermitConsts.MEASURE_LEVEL_CATEGORY, "指标分类"),
    MEASURE_L3(DpermitConsts.TYPE_MEASURE_L3, DpermitConsts.TYPE_MEASURE, DpermitConsts.MEASURE_LEVEL_MEASURE, "指标"),

    PRODUCT(DpermitConsts.TYPE_PRODUCT, DpermitConsts.TYPE_PRODUCT, 0, "产品"),
    PRODUCT_L1(DpermitConsts.TYPE_PRODUCT_BIZTYPE, DpermitConsts.TYPE_PRODUCT, DpermitConsts.PRODUCT_LEVEL_BIZTYPE, "业务类型"),
    PRODUCT_L2(DpermitConsts.TYPE_PRODUCT_BIZLINE, DpermitConsts.TYPE_PRODUCT, DpermitConsts.PRODUCT_LEVEL_BIZLINE, "业务线"),
    PRODUCT_L3(DpermitConsts.TYPE_PRODUCT_PRODUCTGROUP, DpermitConsts.TYPE_PRODUCT, DpermitConsts.PRODUCT_LEVEL_PRODUCTGROUP, "产品组"),

    PROMOTION(DpermitConsts.TYPE_PROMOTION, DpermitConsts.TYPE_PROMOTION, 0, "推广"),
    PROMOTION_COOPERATION_TWO(DpermitConsts.TYPE_PROMOTION_ONE, DpermitConsts.TYPE_PROMOTION, DpermitConsts.PROMOTION_LEVEL_ONE, "二级合作"),
    PROMOTION_MARKETING_ACCOUNT_ONE(DpermitConsts.TYPE_PROMOTION_TWO, DpermitConsts.TYPE_PROMOTION, DpermitConsts.PROMOTION_LEVEL_TWO, "营销一级账户"),
    PROMOTION_MARKETING_ACCOUNT_TWO(DpermitConsts.TYPE_PROMOTION_THR, DpermitConsts.TYPE_PROMOTION, DpermitConsts.PROMOTION_LEVEL_THR, "营销二级账户"),

    CHANNEL(DpermitConsts.TYPE_CHANNEL, DpermitConsts.TYPE_CHANNEL, 0, "渠道"),
    CHANNEL_ONE(DpermitConsts.TYPE_CHANNEL_ONE, DpermitConsts.TYPE_CHANNEL, DpermitConsts.CHANNEL_LEVEL_ONE, "一级渠道"),
    CHANNEL_TWO(DpermitConsts.TYPE_CHANNEL_TWO, DpermitConsts.TYPE_CHANNEL, DpermitConsts.CHANNEL_LEVEL_TWO, "二级渠道"),
    CHANNEL_THR(DpermitConsts.TYPE_CHANNEL_THR, DpermitConsts.TYPE_CHANNEL, DpermitConsts.CHANNEL_LEVEL_THR, "三级渠道"),
    ;


    private final int value;      // 数据权限类型
    private final int type;       // 基础数据权限类型
    private final int level;      // 数据权限层级
    private final String name;      // 名称

    private DpermitEnum(int value, int type, int level, String name) {
        this.value = value;
        this.type = type;
        this.level = level;
        this.name = name;
    }


    public int getValue() {
        return value;
    }

    public int getType() {
        return type;
    }

    public int getLevel() {
        return level;
    }

    public String getName() {
        return name;
    }

    /**
     * 根据value返回枚举类型，主要在switch中使用
     *
     * @param value
     * @return
     */
    public static DpermitEnum getByValue(int value) {
        for (DpermitEnum dpermitEnum : values()) {
            if (dpermitEnum.getValue() == value) {
                return dpermitEnum;
            }
        }
        return null;
    }


    /**
     * 获取某个维度数据权限
     *
     * @param type 数据权限基础类型  eg. 组织架构、区域、渠道
     * @return
     */
    public static List<DpermitEnum> listByType(int type) {
        List<DpermitEnum> dpermitEnums = Lists.newArrayListWithCapacity(4);
        for (DpermitEnum dpermitEnum : values()) {
            if (dpermitEnum.getType() == type) {
                dpermitEnums.add(dpermitEnum);
            }
        }
        return dpermitEnums;
    }
}
